{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "initial_id",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T02:01:20.371391300Z",
     "start_time": "2024-08-22T02:01:20.343396800Z"
    }
   },
   "outputs": [],
   "source": [
    "print(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3189746890eea727",
   "metadata": {
    "ExecuteTime": {
     "start_time": "2024-08-22T02:04:47.749188600Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": [
    "!pip install mlrun"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6909fbbd96025354",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T04:00:59.573016900Z",
     "start_time": "2024-08-22T04:00:57.896025200Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": [
    "import json\n",
    "import mlrun\n",
    "mlrun.set_environment(\"http://mlapi.feg.cn\", access_key=\"\", username=\"\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b0b95fc1-5c2e-48a7-ad7e-fbc82381f8fa",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# 创建一个新项目\n",
    "project = mlrun.get_or_create_project(\"tutorial\", \"./\", user_project=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "9e685ee8-d5aa-4bf5-97f7-0f6e75c277ca",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T03:53:37.563785400Z",
     "start_time": "2024-08-22T03:53:37.476785700Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Writing data-prep.py\n"
     ]
    }
   ],
   "source": [
    "%%writefile data-prep.py\n",
    "\n",
    "import pandas as pd\n",
    "from sklearn.datasets import load_breast_cancer\n",
    "\n",
    "\n",
    "\n",
    "@mlrun.handler(outputs=[\"dataset\", \"label_column\"])\n",
    "def breast_cancer_generator():\n",
    "    \"\"\"\n",
    "    A function which generates the breast cancer dataset\n",
    "    \"\"\"\n",
    "    breast_cancer = load_breast_cancer()\n",
    "    breast_cancer_dataset = pd.DataFrame(\n",
    "        data=breast_cancer.data, columns=breast_cancer.feature_names\n",
    "    )\n",
    "    breast_cancer_labels = pd.DataFrame(data=breast_cancer.target, columns=[\"label\"])\n",
    "    breast_cancer_dataset = pd.concat(\n",
    "        [breast_cancer_dataset, breast_cancer_labels], axis=1\n",
    "    )\n",
    "\n",
    "    return breast_cancer_dataset, \"label\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "fb4cee2bf2949dea",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T03:55:07.681199900Z",
     "start_time": "2024-08-22T03:55:06.622266600Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<mlrun.projects.project.MlrunProject at 0x190648d5f00>"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 从上面的代码创建一个无服务器函数对象，并将其注册到项目中\n",
    "data_gen_fn = project.set_function(\n",
    "    \"data-prep.py\",\n",
    "    name=\"data-prep\",\n",
    "    kind=\"job\",\n",
    "    image=\"mlrun/mlrun\",\n",
    "    handler=\"breast_cancer_generator\",\n",
    ")\n",
    "project.save()  # save the project with the latest config"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "9edd2d6fa45cb4fa",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-08-22T03:58:07.412849900Z",
     "start_time": "2024-08-22T03:58:03.043747800Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "> 2024-08-22 11:58:03,332 [info] Storing function: {'name': 'data-prep-breast-cancer-generator', 'uid': '947e5fff323144a08be6782791adf062', 'db': 'http://mlapi.feg.cn'}\n",
      "> 2024-08-22 11:58:06,163 [error] Run error, Traceback (most recent call last):\n",
      "  File \"D:\\Tools\\Path\\Python\\.pyenv\\pyenv-win\\versions\\3.10.0\\lib\\site-packages\\mlrun\\runtimes\\local.py\", line 295, in _run\n",
      "    fn = self._get_handler(handler, context)\n",
      "  File \"D:\\Tools\\Path\\Python\\.pyenv\\pyenv-win\\versions\\3.10.0\\lib\\site-packages\\mlrun\\runtimes\\local.py\", line 231, in _get_handler\n",
      "    return load_module(command, handler, context)\n",
      "  File \"D:\\Tools\\Path\\Python\\.pyenv\\pyenv-win\\versions\\3.10.0\\lib\\site-packages\\mlrun\\runtimes\\local.py\", line 385, in load_module\n",
      "    spec.loader.exec_module(module)\n",
      "  File \"<frozen importlib._bootstrap_external>\", line 883, in exec_module\n",
      "  File \"<frozen importlib._bootstrap>\", line 241, in _call_with_frames_removed\n",
      "  File \"D:\\WorkSpace\\gitee\\leetcode\\jupyter\\data-prep.py\", line 7, in <module>\n",
      "    @mlrun.handler(outputs=[\"dataset\", \"label_column\"])\n",
      "NameError: name 'mlrun' is not defined\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<style>\n",
       ".dictlist {\n",
       "  background-color: #4EC64B;\n",
       "  text-align: center;\n",
       "  margin: 4px;\n",
       "  border-radius: 3px; padding: 0px 3px 1px 3px; display: inline-block;}\n",
       ".artifact {\n",
       "  cursor: pointer;\n",
       "  background-color: #4EC64B;\n",
       "  text-align: left;\n",
       "  margin: 4px; border-radius: 3px; padding: 0px 3px 1px 3px; display: inline-block;\n",
       "}\n",
       "div.block.hidden {\n",
       "  display: none;\n",
       "}\n",
       ".clickable {\n",
       "  cursor: pointer;\n",
       "}\n",
       ".ellipsis {\n",
       "  display: inline-block;\n",
       "  max-width: 60px;\n",
       "  white-space: nowrap;\n",
       "  overflow: hidden;\n",
       "  text-overflow: ellipsis;\n",
       "}\n",
       ".master-wrapper {\n",
       "  display: flex;\n",
       "  flex-flow: row nowrap;\n",
       "  justify-content: flex-start;\n",
       "  align-items: stretch;\n",
       "}\n",
       ".master-tbl {\n",
       "  flex: 3\n",
       "}\n",
       ".master-wrapper > div {\n",
       "  margin: 4px;\n",
       "  padding: 10px;\n",
       "}\n",
       "iframe.fileview {\n",
       "  border: 0 none;\n",
       "  height: 100%;\n",
       "  width: 100%;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       ".pane-header-title {\n",
       "  width: 80%;\n",
       "  font-weight: 500;\n",
       "}\n",
       ".pane-header {\n",
       "  line-height: 1;\n",
       "  background-color: #4EC64B;\n",
       "  padding: 3px;\n",
       "}\n",
       ".pane-header .close {\n",
       "  font-size: 20px;\n",
       "  font-weight: 700;\n",
       "  float: right;\n",
       "  margin-top: -5px;\n",
       "}\n",
       ".master-wrapper .right-pane {\n",
       "  border: 1px inset silver;\n",
       "  width: 40%;\n",
       "  min-height: 300px;\n",
       "  flex: 3\n",
       "  min-width: 500px;\n",
       "}\n",
       ".master-wrapper * {\n",
       "  box-sizing: border-box;\n",
       "}\n",
       "</style><script>\n",
       "function copyToClipboard(fld) {\n",
       "    if (document.queryCommandSupported && document.queryCommandSupported('copy')) {\n",
       "        var textarea = document.createElement('textarea');\n",
       "        textarea.textContent = fld.innerHTML;\n",
       "        textarea.style.position = 'fixed';\n",
       "        document.body.appendChild(textarea);\n",
       "        textarea.select();\n",
       "\n",
       "        try {\n",
       "            return document.execCommand('copy'); // Security exception may be thrown by some browsers.\n",
       "        } catch (ex) {\n",
       "\n",
       "        } finally {\n",
       "            document.body.removeChild(textarea);\n",
       "        }\n",
       "    }\n",
       "}\n",
       "function expandPanel(el) {\n",
       "  const panelName = \"#\" + el.getAttribute('paneName');\n",
       "  console.log(el.title);\n",
       "\n",
       "  document.querySelector(panelName + \"-title\").innerHTML = el.title\n",
       "  iframe = document.querySelector(panelName + \"-body\");\n",
       "\n",
       "  const tblcss = `<style> body { font-family: Arial, Helvetica, sans-serif;}\n",
       "    #csv { margin-bottom: 15px; }\n",
       "    #csv table { border-collapse: collapse;}\n",
       "    #csv table td { padding: 4px 8px; border: 1px solid silver;} </style>`;\n",
       "\n",
       "  function csvToHtmlTable(str) {\n",
       "    return '<div id=\"csv\"><table><tr><td>' +  str.replace(/[\\n\\r]+$/g, '').replace(/[\\n\\r]+/g, '</td></tr><tr><td>')\n",
       "      .replace(/,/g, '</td><td>') + '</td></tr></table></div>';\n",
       "  }\n",
       "\n",
       "  function reqListener () {\n",
       "    if (el.title.endsWith(\".csv\")) {\n",
       "      iframe.setAttribute(\"srcdoc\", tblcss + csvToHtmlTable(this.responseText));\n",
       "    } else {\n",
       "      iframe.setAttribute(\"srcdoc\", this.responseText);\n",
       "    }\n",
       "    console.log(this.responseText);\n",
       "  }\n",
       "\n",
       "  const oReq = new XMLHttpRequest();\n",
       "  oReq.addEventListener(\"load\", reqListener);\n",
       "  oReq.open(\"GET\", el.title);\n",
       "  oReq.send();\n",
       "\n",
       "\n",
       "  //iframe.src = el.title;\n",
       "  const resultPane = document.querySelector(panelName + \"-pane\");\n",
       "  if (resultPane.classList.contains(\"hidden\")) {\n",
       "    resultPane.classList.remove(\"hidden\");\n",
       "  }\n",
       "}\n",
       "function closePanel(el) {\n",
       "  const panelName = \"#\" + el.getAttribute('paneName')\n",
       "  const resultPane = document.querySelector(panelName + \"-pane\");\n",
       "  if (!resultPane.classList.contains(\"hidden\")) {\n",
       "    resultPane.classList.add(\"hidden\");\n",
       "  }\n",
       "}\n",
       "\n",
       "</script>\n",
       "<div class=\"master-wrapper\">\n",
       "  <div class=\"block master-tbl\"><div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>project</th>\n",
       "      <th>uid</th>\n",
       "      <th>iter</th>\n",
       "      <th>start</th>\n",
       "      <th>state</th>\n",
       "      <th>name</th>\n",
       "      <th>labels</th>\n",
       "      <th>inputs</th>\n",
       "      <th>parameters</th>\n",
       "      <th>results</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>tutorial-a1122</td>\n",
       "      <td><div title=\"947e5fff323144a08be6782791adf062\"><a href=\"http://mlrun.feg.cn/projects/tutorial-a1122/jobs/monitor/947e5fff323144a08be6782791adf062/overview\" target=\"_blank\" >...91adf062</a></div></td>\n",
       "      <td>0</td>\n",
       "      <td>Aug 22 03:58:05</td>\n",
       "      <td><div style=\"color: red;\" title=\"Failed on pre-loading / post-running of the function, caused by: name 'mlrun' is not defined\">error</div></td>\n",
       "      <td>data-prep-breast-cancer-generator</td>\n",
       "      <td><div class=\"dictlist\">kind=local</div><div class=\"dictlist\">owner=a1122</div><div class=\"dictlist\">host=DESKTOP-VPT6UGB</div></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div></div>\n",
       "  <div id=\"result1b5075a8-pane\" class=\"right-pane block hidden\">\n",
       "    <div class=\"pane-header\">\n",
       "      <span id=\"result1b5075a8-title\" class=\"pane-header-title\">Title</span>\n",
       "      <span onclick=\"closePanel(this)\" paneName=\"result1b5075a8\" class=\"close clickable\">&times;</span>\n",
       "    </div>\n",
       "    <iframe class=\"fileview\" id=\"result1b5075a8-body\"></iframe>\n",
       "  </div>\n",
       "</div>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    },
    {
     "data": {
      "text/html": [
       "<b> > to track results use the .show() or .logs() methods  or <a href=\"http://mlrun.feg.cn/projects/tutorial-a1122/jobs/monitor/947e5fff323144a08be6782791adf062/overview\" target=\"_blank\">click here</a> to open in UI</b>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "> 2024-08-22 11:58:06,791 [info] Run execution finished: {'status': 'error', 'name': 'data-prep-breast-cancer-generator'}\n"
     ]
    },
    {
     "ename": "RunError",
     "evalue": "Failed on pre-loading / post-running of the function, caused by: name 'mlrun' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mRunError\u001b[0m                                  Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[20], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m gen_data_run \u001b[38;5;241m=\u001b[39m \u001b[43mproject\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun_function\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mdata-prep\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mlocal\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\Tools\\Path\\Python\\.pyenv\\pyenv-win\\versions\\3.10.0\\lib\\site-packages\\mlrun\\projects\\project.py:2942\u001b[0m, in \u001b[0;36mMlrunProject.run_function\u001b[1;34m(self, function, handler, name, params, hyperparams, hyper_param_options, inputs, outputs, workdir, labels, base_task, watch, local, verbose, selector, auto_build, schedule, artifact_path, notifications, returns, builder_env)\u001b[0m\n\u001b[0;32m   2864\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mrun_function\u001b[39m(\n\u001b[0;32m   2865\u001b[0m     \u001b[38;5;28mself\u001b[39m,\n\u001b[0;32m   2866\u001b[0m     function: typing\u001b[38;5;241m.\u001b[39mUnion[\u001b[38;5;28mstr\u001b[39m, mlrun\u001b[38;5;241m.\u001b[39mruntimes\u001b[38;5;241m.\u001b[39mBaseRuntime],\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m   2886\u001b[0m     builder_env: Optional[\u001b[38;5;28mdict\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[0;32m   2887\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m typing\u001b[38;5;241m.\u001b[39mUnion[mlrun\u001b[38;5;241m.\u001b[39mmodel\u001b[38;5;241m.\u001b[39mRunObject, kfp\u001b[38;5;241m.\u001b[39mdsl\u001b[38;5;241m.\u001b[39mContainerOp]:\n\u001b[0;32m   2888\u001b[0m \u001b[38;5;250m    \u001b[39m\u001b[38;5;124;03m\"\"\"Run a local or remote task as part of a local/kubeflow pipeline\u001b[39;00m\n\u001b[0;32m   2889\u001b[0m \n\u001b[0;32m   2890\u001b[0m \u001b[38;5;124;03m    example (use with project)::\u001b[39;00m\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m   2940\u001b[0m \u001b[38;5;124;03m    :return: MLRun RunObject or KubeFlow containerOp\u001b[39;00m\n\u001b[0;32m   2941\u001b[0m \u001b[38;5;124;03m    \"\"\"\u001b[39;00m\n\u001b[1;32m-> 2942\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mrun_function\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m   2943\u001b[0m \u001b[43m        \u001b[49m\u001b[43mfunction\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   2944\u001b[0m \u001b[43m        \u001b[49m\u001b[43mhandler\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mhandler\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   2945\u001b[0m \u001b[43m        \u001b[49m\u001b[43mname\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mname\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   2946\u001b[0m \u001b[43m        \u001b[49m\u001b[43mparams\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mparams\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   2947\u001b[0m \u001b[43m        \u001b[49m\u001b[43mhyperparams\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mhyperparams\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   2948\u001b[0m \u001b[43m        \u001b[49m\u001b[43mhyper_param_options\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mhyper_param_options\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   2949\u001b[0m \u001b[43m        \u001b[49m\u001b[43minputs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   2950\u001b[0m \u001b[43m        \u001b[49m\u001b[43moutputs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43moutputs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   2951\u001b[0m \u001b[43m        \u001b[49m\u001b[43mworkdir\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mworkdir\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   2952\u001b[0m \u001b[43m        \u001b[49m\u001b[43mlabels\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mlabels\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   2953\u001b[0m \u001b[43m        \u001b[49m\u001b[43mbase_task\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mbase_task\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   2954\u001b[0m \u001b[43m        \u001b[49m\u001b[43mwatch\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mwatch\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   2955\u001b[0m \u001b[43m        \u001b[49m\u001b[43mlocal\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mlocal\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   2956\u001b[0m \u001b[43m        \u001b[49m\u001b[43mverbose\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mverbose\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   2957\u001b[0m \u001b[43m        \u001b[49m\u001b[43mselector\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mselector\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   2958\u001b[0m \u001b[43m        \u001b[49m\u001b[43mproject_object\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[0;32m   2959\u001b[0m \u001b[43m        \u001b[49m\u001b[43mauto_build\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mauto_build\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   2960\u001b[0m \u001b[43m        \u001b[49m\u001b[43mschedule\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mschedule\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   2961\u001b[0m \u001b[43m        \u001b[49m\u001b[43martifact_path\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43martifact_path\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   2962\u001b[0m \u001b[43m        \u001b[49m\u001b[43mnotifications\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mnotifications\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   2963\u001b[0m \u001b[43m        \u001b[49m\u001b[43mreturns\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mreturns\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   2964\u001b[0m \u001b[43m        \u001b[49m\u001b[43mbuilder_env\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mbuilder_env\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   2965\u001b[0m \u001b[43m    \u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\Tools\\Path\\Python\\.pyenv\\pyenv-win\\versions\\3.10.0\\lib\\site-packages\\mlrun\\projects\\operations.py:192\u001b[0m, in \u001b[0;36mrun_function\u001b[1;34m(function, handler, name, params, hyperparams, hyper_param_options, inputs, outputs, workdir, labels, base_task, watch, local, verbose, selector, project_object, auto_build, schedule, artifact_path, notifications, returns, builder_env)\u001b[0m\n\u001b[0;32m    190\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m local \u001b[38;5;129;01mand\u001b[39;00m project \u001b[38;5;129;01mand\u001b[39;00m function\u001b[38;5;241m.\u001b[39mspec\u001b[38;5;241m.\u001b[39mbuild\u001b[38;5;241m.\u001b[39msource:\n\u001b[0;32m    191\u001b[0m     workdir \u001b[38;5;241m=\u001b[39m workdir \u001b[38;5;129;01mor\u001b[39;00m project\u001b[38;5;241m.\u001b[39mspec\u001b[38;5;241m.\u001b[39mget_code_path()\n\u001b[1;32m--> 192\u001b[0m run_result \u001b[38;5;241m=\u001b[39m \u001b[43mfunction\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m    193\u001b[0m \u001b[43m    \u001b[49m\u001b[43mname\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mname\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    194\u001b[0m \u001b[43m    \u001b[49m\u001b[43mrunspec\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtask\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    195\u001b[0m \u001b[43m    \u001b[49m\u001b[43mworkdir\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mworkdir\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    196\u001b[0m \u001b[43m    \u001b[49m\u001b[43mverbose\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mverbose\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    197\u001b[0m \u001b[43m    \u001b[49m\u001b[43mwatch\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mwatch\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    198\u001b[0m \u001b[43m    \u001b[49m\u001b[43mlocal\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mlocal\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    199\u001b[0m \u001b[43m    \u001b[49m\u001b[43martifact_path\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43martifact_path\u001b[49m\n\u001b[0;32m    200\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;66;43;03m# workflow artifact_path has precedence over the project artifact_path equivalent to\u001b[39;49;00m\n\u001b[0;32m    201\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;66;43;03m# passing artifact_path to function.run() has precedence over the project.artifact_path and the default one\u001b[39;49;00m\n\u001b[0;32m    202\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;129;43;01mor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mpipeline_context\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mworkflow_artifact_path\u001b[49m\n\u001b[0;32m    203\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;129;43;01mor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43m(\u001b[49m\u001b[43mproject\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43martifact_path\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mproject\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01melse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    204\u001b[0m \u001b[43m    \u001b[49m\u001b[43mauto_build\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mauto_build\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    205\u001b[0m \u001b[43m    \u001b[49m\u001b[43mschedule\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mschedule\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    206\u001b[0m \u001b[43m    \u001b[49m\u001b[43mnotifications\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mnotifications\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    207\u001b[0m \u001b[43m    \u001b[49m\u001b[43mbuilder_env\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mbuilder_env\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    208\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    209\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m run_result:\n\u001b[0;32m    210\u001b[0m     run_result\u001b[38;5;241m.\u001b[39m_notified \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mFalse\u001b[39;00m\n",
      "File \u001b[1;32mD:\\Tools\\Path\\Python\\.pyenv\\pyenv-win\\versions\\3.10.0\\lib\\site-packages\\mlrun\\runtimes\\base.py:392\u001b[0m, in \u001b[0;36mBaseRuntime.run\u001b[1;34m(self, runspec, handler, name, project, params, inputs, out_path, workdir, artifact_path, watch, schedule, hyperparams, hyper_param_options, verbose, scrape_metrics, local, local_code_path, auto_build, param_file_secrets, notifications, returns, state_thresholds, **launcher_kwargs)\u001b[0m\n\u001b[0;32m    335\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m    336\u001b[0m \u001b[38;5;124;03mRun a local or remote task.\u001b[39;00m\n\u001b[0;32m    337\u001b[0m \n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    387\u001b[0m \u001b[38;5;124;03m:return: Run context object (RunObject) with run metadata, results and status\u001b[39;00m\n\u001b[0;32m    388\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m    389\u001b[0m launcher \u001b[38;5;241m=\u001b[39m mlrun\u001b[38;5;241m.\u001b[39mlauncher\u001b[38;5;241m.\u001b[39mfactory\u001b[38;5;241m.\u001b[39mLauncherFactory()\u001b[38;5;241m.\u001b[39mcreate_launcher(\n\u001b[0;32m    390\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_is_remote, local\u001b[38;5;241m=\u001b[39mlocal, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mlauncher_kwargs\n\u001b[0;32m    391\u001b[0m )\n\u001b[1;32m--> 392\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mlauncher\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mlaunch\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m    393\u001b[0m \u001b[43m    \u001b[49m\u001b[43mruntime\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[0;32m    394\u001b[0m \u001b[43m    \u001b[49m\u001b[43mtask\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrunspec\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    395\u001b[0m \u001b[43m    \u001b[49m\u001b[43mhandler\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mhandler\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    396\u001b[0m \u001b[43m    \u001b[49m\u001b[43mname\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mname\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    397\u001b[0m \u001b[43m    \u001b[49m\u001b[43mproject\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mproject\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    398\u001b[0m \u001b[43m    \u001b[49m\u001b[43mparams\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mparams\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    399\u001b[0m \u001b[43m    \u001b[49m\u001b[43minputs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    400\u001b[0m \u001b[43m    \u001b[49m\u001b[43mout_path\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mout_path\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    401\u001b[0m \u001b[43m    \u001b[49m\u001b[43mworkdir\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mworkdir\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    402\u001b[0m \u001b[43m    \u001b[49m\u001b[43martifact_path\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43martifact_path\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    403\u001b[0m \u001b[43m    \u001b[49m\u001b[43mwatch\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mwatch\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    404\u001b[0m \u001b[43m    \u001b[49m\u001b[43mschedule\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mschedule\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    405\u001b[0m \u001b[43m    \u001b[49m\u001b[43mhyperparams\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mhyperparams\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    406\u001b[0m \u001b[43m    \u001b[49m\u001b[43mhyper_param_options\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mhyper_param_options\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    407\u001b[0m \u001b[43m    \u001b[49m\u001b[43mverbose\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mverbose\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    408\u001b[0m \u001b[43m    \u001b[49m\u001b[43mscrape_metrics\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mscrape_metrics\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    409\u001b[0m \u001b[43m    \u001b[49m\u001b[43mlocal_code_path\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mlocal_code_path\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    410\u001b[0m \u001b[43m    \u001b[49m\u001b[43mauto_build\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mauto_build\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    411\u001b[0m \u001b[43m    \u001b[49m\u001b[43mparam_file_secrets\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mparam_file_secrets\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    412\u001b[0m \u001b[43m    \u001b[49m\u001b[43mnotifications\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mnotifications\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    413\u001b[0m \u001b[43m    \u001b[49m\u001b[43mreturns\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mreturns\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    414\u001b[0m \u001b[43m    \u001b[49m\u001b[43mstate_thresholds\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstate_thresholds\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    415\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\Tools\\Path\\Python\\.pyenv\\pyenv-win\\versions\\3.10.0\\lib\\site-packages\\mlrun\\launcher\\local.py:123\u001b[0m, in \u001b[0;36mClientLocalLauncher.launch\u001b[1;34m(self, runtime, task, handler, name, project, params, inputs, out_path, workdir, artifact_path, watch, schedule, hyperparams, hyper_param_options, verbose, scrape_metrics, local_code_path, auto_build, param_file_secrets, notifications, returns, state_thresholds)\u001b[0m\n\u001b[0;32m    103\u001b[0m run \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_enrich_run(\n\u001b[0;32m    104\u001b[0m     runtime\u001b[38;5;241m=\u001b[39mruntime,\n\u001b[0;32m    105\u001b[0m     run\u001b[38;5;241m=\u001b[39mrun,\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    120\u001b[0m     state_thresholds\u001b[38;5;241m=\u001b[39mstate_thresholds,\n\u001b[0;32m    121\u001b[0m )\n\u001b[0;32m    122\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_validate_runtime(runtime, run)\n\u001b[1;32m--> 123\u001b[0m result \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_execute\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m    124\u001b[0m \u001b[43m    \u001b[49m\u001b[43mruntime\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mruntime\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    125\u001b[0m \u001b[43m    \u001b[49m\u001b[43mrun\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    126\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    128\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m result\n",
      "File \u001b[1;32mD:\\Tools\\Path\\Python\\.pyenv\\pyenv-win\\versions\\3.10.0\\lib\\site-packages\\mlrun\\launcher\\local.py:198\u001b[0m, in \u001b[0;36mClientLocalLauncher._execute\u001b[1;34m(self, runtime, run)\u001b[0m\n\u001b[0;32m    195\u001b[0m \u001b[38;5;66;03m# run post run hooks\u001b[39;00m\n\u001b[0;32m    196\u001b[0m runtime\u001b[38;5;241m.\u001b[39m_post_run(result, execution)  \u001b[38;5;66;03m# hook for runtime specific cleanup\u001b[39;00m\n\u001b[1;32m--> 198\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_wrap_run_result\u001b[49m\u001b[43m(\u001b[49m\u001b[43mruntime\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mresult\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43merr\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mlast_err\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\Tools\\Path\\Python\\.pyenv\\pyenv-win\\versions\\3.10.0\\lib\\site-packages\\mlrun\\launcher\\base.py:414\u001b[0m, in \u001b[0;36mBaseLauncher._wrap_run_result\u001b[1;34m(self, runtime, result, run, schedule, err)\u001b[0m\n\u001b[0;32m    408\u001b[0m         \u001b[38;5;28;01mif\u001b[39;00m runtime\u001b[38;5;241m.\u001b[39m_is_remote \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m runtime\u001b[38;5;241m.\u001b[39mis_child:\n\u001b[0;32m    409\u001b[0m             logger\u001b[38;5;241m.\u001b[39merror(\n\u001b[0;32m    410\u001b[0m                 \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mRun did not finish successfully\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m    411\u001b[0m                 state\u001b[38;5;241m=\u001b[39mrun\u001b[38;5;241m.\u001b[39mstatus\u001b[38;5;241m.\u001b[39mstate,\n\u001b[0;32m    412\u001b[0m                 status\u001b[38;5;241m=\u001b[39mrun\u001b[38;5;241m.\u001b[39mstatus\u001b[38;5;241m.\u001b[39mto_dict(),\n\u001b[0;32m    413\u001b[0m             )\n\u001b[1;32m--> 414\u001b[0m         \u001b[38;5;28;01mraise\u001b[39;00m mlrun\u001b[38;5;241m.\u001b[39mruntimes\u001b[38;5;241m.\u001b[39mutils\u001b[38;5;241m.\u001b[39mRunError(run\u001b[38;5;241m.\u001b[39merror)\n\u001b[0;32m    415\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m run\n\u001b[0;32m    417\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n",
      "\u001b[1;31mRunError\u001b[0m: Failed on pre-loading / post-running of the function, caused by: name 'mlrun' is not defined"
     ]
    }
   ],
   "source": [
    "gen_data_run = project.run_function(\"data-prep\", local=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5fbd141bf337bb03",
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
